package com.minova.demo.service.impl;

import com.minova.demo.entity.TzBasket;
import com.minova.demo.mapper.TzBasketMapper;
import com.minova.demo.service.ITzBasketService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author linrongji
 * @since 2019-12-23
 */
@Service
public class TzBasketServiceImpl extends ServiceImpl<TzBasketMapper, TzBasket> implements ITzBasketService {

	@Autowired
	private TzBasketMapper tzBaskeMapper;
	
	@Override
	public List<TzBasket> selectBasketByUserId(String userId) {
		// TODO Auto-generated method stub
		return tzBaskeMapper.selectBasketByUserId(userId);
	}

	@Override
	public void saveBasket(TzBasket tzBaskets) {
		// TODO Auto-generated method stub
		tzBaskeMapper.saveBasket(tzBaskets);
	}

	@Override
	public List<TzBasket> selectById(String ids) {
		List<TzBasket> tzBaskets = new ArrayList<TzBasket>();
		List<Long> basketIds = JSON.parseArray(ids, Long.class);
		for (Long id : basketIds) {
			tzBaskets.add(tzBaskeMapper.selectBasketById(id));
		}
		return tzBaskets;
	}

}
